package com.ytjj.qmyx.mall.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.common.controller.BaseController;
import com.ytjj.qmyx.mall.service.FrontCategoryService;
import com.ytjj.qmyx.mall.service.SpecialService;
import com.ytjj.qmyx.users.client.AdminClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 专栏控制器
 *
 *
 * @version 1.0
 *
 */
@RestController
@RequestMapping("/special")
public class SpecialController extends BaseController {

    private final SpecialService specialService;

    @Resource
    private AdminClient adminClient;

    @Autowired
    FrontCategoryService frontCategoryService;


    public SpecialController(SpecialService specialService) {
        this.specialService = specialService;
    }

    /**
     * 获取专栏列表
     * 2021/9/15修改成获取一级分类
     * @param type
     * @param isHomeShow
     * @return
     */
    @GetMapping("/getSpecialList")
    public CommonResult getSpecialList(@RequestParam("type") String type,
                                       @RequestParam("isHomeShow") Integer isHomeShow){
        return CommonResult.success(frontCategoryService.getFrontListByType(1, 0));
    }

    /**
     * 获取专栏信息
     *
     * @param specialId
     * @return
     */
    @GetMapping("/getSpecialInfo")
    public CommonResult getSpecialInfo(@RequestParam("specialId") Integer specialId){
        return CommonResult.success(specialService.getSpecialInfo(specialId));
    }

    /**
     * 获取研究所专栏列表
     *
     * @param type
     * @return
     */
    @GetMapping("/getGraduateSpecialList")
    public CommonResult getGraduateSpecialList(@RequestParam("type") String type){
        return CommonResult.success(specialService.getGraduateSpecialListByType(type));
    }

    /**
     * 获取研究所商品列表
     *
     * @return
     */
    @GetMapping("/getGraduateProductList")
    public CommonResult getGraduateProductList(@RequestParam("specialId") Integer specialId){
        return CommonResult.success(specialService.getGraduateProductList(specialId));
    }

    /**
     *
     * @param specialId
     * @return
     */
//    @GetMapping("/getRecommendProductList")
//    public CommonResult getRecommendProductList(@RequestParam("specialId") Integer specialId){
//        return CommonResult.success(specialService.getRecommendProductList(specialId));
//    }

    /**
     * 查询动态分类
     *
     * type = APP_DYNAMIC_CATEGORY -app首页动态分类
     */
    @GetMapping("/getDynamicCategory")
    public CommonResult getDynamicCategory(){
        return adminClient.getDynamicCategory();
    }



    /**
     * 获取多级分类专栏列表
     * @param status
     * @return
     */
    @GetMapping("/getNewSpecialList")
    public CommonResult getNewSpecialList(@RequestParam(value = "status" ,required = false) Integer status, @RequestParam("pid") Integer pid) {
        return CommonResult.success(frontCategoryService.getFrontListByType(status, pid));
    }
}
